#!perl

use strict;
use Term::ANSIColor qw( :constants );

our $VERSION = '1.0.0';

my %identity = (
);

my %syntax = (
  diff => {
    '^Only in .*'                            => RED,
    '^Files .* and .* are identical$'        => RED,
    '^Files .* and .* differ$'               => RED,
    '^Binary files .* and .* differ$'        => RED,
    '^File .* is a .* while file .* is a .*' => RED,
    '^No newline at end of file .*'          => RED,
    '^-.*'                                   => MAGENTA,
    '^<.*'                                   => MAGENTA,
    '^\+.*'                                  => WHITE . BOLD,
    '^>.*'                                   => WHITE . BOLD,
    '^! .*'                                  => YELLOW,
    '^\<\d\+\>.*'                            => GREEN,
    '^\*\*\*\*.*'                            => GREEN,
    '^\d+(,\d+)?[cda]\d+(,\d+)?.*'           => GREEN,
    '^diff.*'                                => GREEN,
    '^\+\+\+ .*'                             => GREEN,
    '^Index: .*$'                            => GREEN,
    '^==== .*$'                              => GREEN,
    '^\*\*\* .*'                             => BLUE,
    '^--- .*'                                => BLUE,
    '^#.*'                                   => BLUE,
  }
);

my $match = undef;
if( $ARGV[0] ){
 $match = $syntax{$ARGV[0]};
}else{
 $match = $syntax{'diff'};
}

foreach my $ln (<STDIN>) {
  chomp($ln);
  my $format = undef;
  if($match) {
    foreach my $re (keys %{$match}) {
      if($ln =~ /$re/) {
        $format = $match->{$re};
        last;
      }
    }
  }
  print(($format ? "$format$ln" . RESET : $ln), "\n");
}
